﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AutoAddClient
{
    class Program
    {
        static void Main(string[] args)
        {
            AddMaxMinExceptDevice();
        }

        static void AddMaxMinExceptDevice()
        {
            var clientService = AutoAddClient.AutoAddService.GetClientRepository();
            var max = System.DateTime.Now;
            var min = clientService.GetList().Max(d => d.AddTime);
            Console.WriteLine("最新安装的时间" + min.ToString("yyyy-MM-dd HH:mm:ss.fff"));

            var exceptHour = new Dictionary<int, int>();
            exceptHour.Add(2, 5);
            Console.Write("请输入要添加的数量(默认为20)：");
            var input = Console.ReadLine();
            var count = 0;
            int.TryParse(input, out count);
            if (count <= 0)
            {
                count = 20;
            }
            Console.WriteLine("系统正在生成数据(自动屏蔽凌晨2-5点的时间)");
            var data = AutoAddService.RandMaxMinExceptDevice(count, min, max, exceptHour);
            data = data.OrderBy(d => d.AddTime).ToList();
            Console.Write("是否显示生成数据(y 是, n 取消) : ");
            input = Console.ReadLine();
            if (input.ToLower().CompareTo("y") == 0)
            {
                WriteLine(data);
            }

            Console.Write("确定添加数据(y 确定 , r 重来, e 退出) : ");
            input = Console.ReadLine().ToLower();
            if (input.CompareTo("y") == 0)
            {
                Console.WriteLine("正在添加数据...");
                AutoAddService.Add(data);
                Console.Write("是否继续添加(y 是, n 退出) : ");
                input = Console.ReadLine().ToLower();
                if (input.CompareTo("y") == 0)
                {
                    Console.WriteLine("-----------------------------------------------------");
                    Console.WriteLine("");
                    AddMaxMinExceptDevice();
                }
            }
            else if (input.CompareTo("r") == 0)
            {
                Console.WriteLine("-----------------------------------------------------");
                Console.WriteLine("");
                AddMaxMinExceptDevice();
            }
            else
            { }
        }

        static void AddCurrentDayDevice()
        {
            var data = AutoAddService.RandCurrentDayDevice(10);
            data = data.OrderBy(d => d.AddTime).ToList();
            AutoAddService.Add(data);
        }

        static void AddYesterdayDevice()
        {
            var data = AutoAddService.RandYesterdayDevice(10);
            data = data.OrderBy(d => d.AddTime).ToList();
            AutoAddService.Add(data);
        }

        static void AddMaxMinDevice()
        {
            var max = System.DateTime.Now;
            var clientService = AutoAddClient.AutoAddService.GetClientRepository();
            var min = clientService.GetList().Max(d => d.AddTime);
            var data = AutoAddService.RandMaxMinDevice(10, min, max);
            data = data.OrderBy(d => d.AddTime).ToList();
            //AutoAddService.Add(data);
        }

        static void DebugWriteLine(IList<Domain.Entity.MobileClient> data)
        {
            foreach (var item in data)
            {
                var json = Newtonsoft.Json.JsonConvert.SerializeObject(item);
                Debug.WriteLine(json);
                Debug.WriteLine("------------------------------------");
            }
        }

        static void WriteLine(IList<Domain.Entity.MobileClient> data)
        {
            foreach (var item in data)
            {
                var json = Newtonsoft.Json.JsonConvert.SerializeObject(item);
                Console.WriteLine(json);
                Console.WriteLine("------------------------------------");
            }
        }
    }
}
